package com.ysh.springdemo;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/login")
    public Boolean login(String userName, String passWord, HttpSession session){
        //参数校验
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(passWord)){
            return false;
        }
        if("admin".equals(userName)&&"123456".equals(passWord)){
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }
    @RequestMapping("/getLoginUser")
    public String getLoginUser(HttpSession session){
        return session.getAttribute("userName").toString();
    }
}
